//
//  ViewController.m
//  UIHorizontalTableViewDemo
//
//  Created by deput on 5/30/15.
//  Copyright (c) 2015 deput. All rights reserved.
//

#import "ViewController.h"
#import "UIHorizontalTableView.h"
#import "UIColor+extend.h"
#import "TableViewCell.h"
@interface ViewController ()<UIHorizontalTableViewDelegate, UITableViewDataSource>{
    UIHorizontalTableView *_tableView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tableView = [[UIHorizontalTableView alloc] initWithFrame:(CGRect){0,0,self.view.bounds.size.width, self.view.bounds.size.height}];
    [self.view addSubview:_tableView];
    _tableView.hDataSource = self;
    _tableView.hDelegate = self;
    [_tableView registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell"];
}

- (CGFloat) tableView:(UITableView *)tableView widthForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.view.bounds.size.width - 64;
}

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.contentImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg",@(indexPath.row+1)]];
    return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSArray *visibleCell = [_tableView visibleCells];
    for (UITableViewCell *cell in visibleCell) {
        CGPoint centerPoint = [cell.contentView convertPoint:cell.contentView.center toView:self.view];
        CGFloat rate = centerPoint.x/([UIScreen mainScreen].bounds.size.width);
        rate = ABS(rate);
        cell.transform = CGAffineTransformScale(cell.transform, 1-rate, 1-rate);
        NSLog(@"%@",@(rate));
    }
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 9;
}

- (CGFloat) tableView:(UITableView *)tableView widthForHeaderInSection:(NSInteger)section
{
    return 0;
}

@end
